package com.cn.why.film.filmindex.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 分页工具类
 */
public  class PageUtil<T> {
    /**
     * 分页
     * @param page
     * @return
     */
    public Map<String,Object>   getPageList(Integer page, List<T> list){
        Map<String,Object> map = new HashMap<>();
        //查询的总条数
        if(page == null || page == 1){
            page = 1;
        }
        int realPage = page - 1;
        //新的list
        List<T> list2 = new ArrayList<>();
        if(list.size()>0){
            //总页数
            List<Integer> countPage = new ArrayList<>();
            Long count;
            count = (long)list.size()/6+1;
            for (int i = 1;i<=count;i++){
                countPage.add(i);
            }
            int beginPage = realPage * 6;
            int endPage = beginPage + 6;
            if (endPage > list.size()) {
                endPage = list.size();
            }
            list2 = list.subList(beginPage, endPage);
            //存入map中
            map.put("list",list2);
            map.put("countPage",countPage);
            System.out.println("当前页数为："+page+"   总页数为："+count);
        }
        return map;
    }
}
